﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Media.Imaging;

namespace Freshome.m.mds
{
    // Recipe type
    public sealed class Recipe : Shortype<Rmt.Recipe>
    {
        public Recipe(Rmt.Recipe pm)
            : base(pm)
        { }
        public Recipe()
            : this(new Rmt.Recipe { Mid = default(short), Name = string.Empty })
        {
            string imageType;
            _pm.ImageData = Bitmaport.InitialImaget(out imageType);
            _pm.ImageType = imageType;
            _pm.Category = Rmt.RecipeCateg.None;
            _pm.Spring = true;
            _pm.Summer = false;
            _pm.Autumn = true;
            _pm.Winter = false;
            _pm.Notes = string.Empty;
            _pm.MeatRiceFarciHot = false;
        }
        public bool Spring
        {
            get { return this._pm.Spring; }
            set
            {
                if (this._pm.Spring != value)
                {
                    this._pm.Spring = value;
                    this.Updated = !this.Created;
                    OnPropertyChanged("Spring");
                }
            }
        }
        public bool Summer
        {
            get { return this._pm.Summer; }
            set
            {
                if (this._pm.Summer != value)
                {
                    this._pm.Summer = value;
                    this.Updated = !this.Created;
                    OnPropertyChanged("Summer");
                }
            }
        }
        public bool Autumn
        {
            get { return this._pm.Autumn; }
            set
            {
                if (this._pm.Autumn != value)
                {
                    this._pm.Autumn = value;
                    this.Updated = !this.Created;
                    OnPropertyChanged("Autumn");
                }
            }
        }
        public bool Winter
        {
            get { return this._pm.Winter; }
            set
            {
                if (this._pm.Winter != value)
                {
                    this._pm.Winter = value;
                    this.Updated = !this.Created;
                    OnPropertyChanged("Winter");
                }
            }
        }
        public bool MeatRiceFarciHot
        {
            get { return this._pm.MeatRiceFarciHot; }
            set
            {
                if (this._pm.MeatRiceFarciHot != value)
                {
                    this._pm.MeatRiceFarciHot = value;
                    this.Updated = !this.Created;
                    OnPropertyChanged("MeatRiceFarciHot");
                }
            }
        }
        public string Name
        {
            get { return this._pm.Name; }
            set
            {
                value = value.Trim();
                if (value.Match(@"^[\S\s]{2,10}$") && this._pm.Name != value)
                {
                    this._pm.Name = value;
                    this.Updated = !Created;
                }
                OnPropertyChanged("Name");
            }
        }
        public byte[] ImageData
        {
            get { return this._pm.ImageData; }
            set
            {
                if (this._pm.ImageData != value && this._pm.ImageData.Length != value.Length)
                {
                    this._pm.ImageData = value;
                    this.Updated = !this.Created;
                    OnPropertyChanged("ImageData");
                }
            }
        }
        public string ImageType
        {
            get { return this._pm.ImageType; }
            set
            {
                value = value.Trim();
                if (value.Match(@"^[\S\s]{2,5}$") && this._pm.ImageType != value)
                {
                    this._pm.ImageType = value;
                    this.Updated = !this.Created;
                    OnPropertyChanged("ImageType");
                }
            }
        }
        public void Bitmapped()
        {
            OnPropertyChanged("Bimage");
        }
        public BitmapImage Bimage
        {
            get
            {
                return Bitmaport.Imaget(_pm.ImageData);
            }
        }
        public override void Refresh(Rmt.Recipe pm)
        {
            _pm.Name = pm.Name;
            _pm.Notes = pm.Notes;
            _pm.Spring = pm.Spring;
            _pm.Summer = pm.Summer;
            _pm.Autumn = pm.Autumn;
            _pm.Winter = pm.Winter;
            _pm.ImageData = pm.ImageData;
            _pm.ImageType = pm.ImageType;
            _pm.MeatRiceFarciHot = pm.MeatRiceFarciHot;
            _pm.Category = pm.Category;
        }
        public bool IsValid
        {
            get
            {
                return _pm.Name.Match(@"^[\S\s]{2,10}$") && _pm.Notes.Match(@"^[\S\s]{0,50}$");
            }
        }
        private ObservableCollection<Steplan> _sps = new ObservableCollection<Steplan>();
        public ObservableCollection<Steplan> Steps
        {
            get
            {
                return this._sps;
            }
        }
        private ObservableCollection<Majorecipe> _mjs = new ObservableCollection<Majorecipe>();
        public ObservableCollection<Majorecipe> Majors
        {
            get
            {
                return this._mjs;
            }
        }
        private ObservableCollection<Minorecipe> _mis = new ObservableCollection<Minorecipe>();
        public ObservableCollection<Minorecipe> Minors
        {
            get
            {
                return this._mis;
            }
        }
    }
    // Steplan
    public sealed class Steplan : Shortype<Rmt.Steplan>
    {
        public Steplan(Rmt.Steplan pm)
            : base(pm)
        { }
        public Steplan()
            : this(new Rmt.Steplan { Mid = default(int), Notes = string.Empty })
        {
        }
        public byte Planum
        {
            get { return this._pm.Planum; }
            set
            {
                if (this._pm.Planum != value)
                {
                    this._pm.Planum = value;
                    this.Updated = !this.Created;
                }
                OnPropertyChanged("Planum");
            }
        }
        public bool IsValid
        {
            get
            {
                return _pm.Notes.Match(@"^[\S\s]{2,50}$");
            }
        }
        public override void Refresh(Rmt.Steplan pm)
        {
            _pm.Planum = pm.Planum;
            _pm.Notes = pm.Notes;
            _pm.Rmx = pm.Rmx;
        }
    }
    // Minorecipe
    public sealed class Minorecipe : Shortype<Rmt.Minorecipe>
    {
        public Minorecipe()
            : this(new Rmt.Minorecipe { Mid = default(int), Notes = string.Empty })
        {
        }
        public Minorecipe(Rmt.Minorecipe pm)
            : base(pm)
        { }
        public bool IsValid
        {
            get
            {
                return _pm.Notes.Match(@"^[\S\s]{0,50}$");
            }
        }
        public override void Refresh(Rmt.Minorecipe pm)
        {
            _pm.Notes = pm.Notes;
            _pm.Parentitle = pm.Parentitle;
            _pm.Imx = pm.Imx;
            _pm.Rmx = pm.Rmx;
        }
    }
    // Majorecipe
    public sealed class Majorecipe : Shortype<Rmt.Majorecipe>
    {
        public Majorecipe()
            : this(new Rmt.Majorecipe { Mid = default(int), Notes = string.Empty })
        {
        }
        public Majorecipe(Rmt.Majorecipe pm)
            : base(pm)
        { }
        public bool Prime
        {
            get { return _pm.Prime; }
            set
            {
                if (this._pm.Prime != value)
                {
                    this._pm.Prime = value;
                    this.Updated = !this.Created;
                }
                OnPropertyChanged("Prime");
            }
        }
        public bool IsValid
        {
            get
            {
                return _pm.Notes.Match(@"^[\S\s]{0,50}$");
            }
        }
        public override void Refresh(Rmt.Majorecipe pm)
        {
            _pm.Notes = pm.Notes;
            _pm.Jmx = pm.Jmx;
            _pm.Rmx = pm.Rmx;
            _pm.Parentitle = pm.Parentitle;
            _pm.Prime = pm.Prime;
        }
    }
}
